public class PalindromeTest {
    public static void main(String[] args) {
        testEmptyList();              // 空链表测试
        testSingleNode();             // 单节点测试
        testEvenLengthPalindrome();   // 偶数长度回文
        testOddLengthPalindrome();    // 奇数长度回文
        testNonPalindrome();          // 非回文测试
        testTwoNodesNotPalindrome();  // 两节点非回文
        testTwoNodesPalindrome();     // 两节点回文
    }

    // 创建链表的辅助方法
    private static LinkedList createLinkedList(int[] values) {
        LinkedList list = new LinkedList();
        if (values == null || values.length == 0) return list;

        list.head = new ListNode(values[0]);
        ListNode current = list.head;
        for (int i = 1; i < values.length; i++) {
            current.next = new ListNode(values[i]);
            current = current.next;
        }
        return list;
    }

    static void testEmptyList() {
        LinkedList list = new LinkedList();
        boolean result = list.checkPalindrome();
        System.out.println("testEmptyList: " + (result == false ? "✓ PASS" : "✗ FAIL"));
    }

    static void testSingleNode() {
        LinkedList list = createLinkedList(new int[]{5});
        boolean result = list.checkPalindrome();
        System.out.println("testSingleNode: " + (result == true ? "✓ PASS" : "✗ FAIL"));
    }

    static void testEvenLengthPalindrome() {
        LinkedList list = createLinkedList(new int[]{1, 2, 2, 1});
        boolean result = list.checkPalindrome();
        System.out.println("testEvenLengthPalindrome: " + (result == true ? "✓ PASS" : "✗ FAIL"));
    }

    static void testOddLengthPalindrome() {
        LinkedList list = createLinkedList(new int[]{1, 2, 3, 2, 1});
        boolean result = list.checkPalindrome();
        System.out.println("testOddLengthPalindrome: " + (result == true ? "✓ PASS" : "✗ FAIL"));
    }

    static void testNonPalindrome() {
        LinkedList list = createLinkedList(new int[]{1, 2, 3});
        boolean result = list.checkPalindrome();
        System.out.println("testNonPalindrome: " + (result == false ? "✓ PASS" : "✗ FAIL"));
    }

    static void testTwoNodesNotPalindrome() {
        LinkedList list = createLinkedList(new int[]{1, 2});
        boolean result = list.checkPalindrome();
        System.out.println("testTwoNodesNotPalindrome: " + (result == false ? "✓ PASS" : "✗ FAIL"));
    }

    static void testTwoNodesPalindrome() {
        LinkedList list = createLinkedList(new int[]{2, 2});
        boolean result = list.checkPalindrome();
        System.out.println("testTwoNodesPalindrome: " + (result == true ? "✓ PASS" : "✗ FAIL"));
    }
}
